/**
 *有效性在线月报
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.WasteWater.dataTransValidation.ValidationMonthDataController', 
			['water.entity.wasteWater.ValidationMonthData','waterCommon','water.common.dateUtil']);

	module.controller('ValidationMonthDataController',function($rootScope,$scope,$ValidationMonthDataService,$waterDataCommon,$DataReportService){
		
		/**
		 * 参数集
		 */
		$scope.queryObj={};
		
		$scope.dataType="month";
		/**
		 * 查询单击事件
		 */
		$scope.onGetListClick;
		
		$scope.onGetListClick=function(){
			_getList();
		}
		 //监听左侧参数变化
		$scope.$on('dataPramChanged', function(event, data) {
			_getList();
	    });
		/**
		 * 导出word
		 */
		$scope.outWord=function(){
			getQueryObjList();
			$ValidationMonthDataService.outWord($scope.queryObj);
		}
		/**
		 * 获取数据源
		 */
		function _getList(){
			getQueryObjList();
			$ValidationMonthDataService.getList($scope.queryObj).then(function(d){
				$scope.ValidationMonthList = d;
			});
		}
		function getQueryObjList(){
			getQueryObj();
			$scope.queryObj.CITYCODE="001002";//默认选择深圳市	
			$scope.queryObj.STATISTICSTYPE="月";
		}
		//初始化日期
		$scope.initQuery = function(){
			if($scope.dataType == "day"){
				$scope.numLimit=13;
			}
			else if($scope.dataType == "month"){
				$scope.numLimit=7;
			}
			// 日查询条件
			if($scope.dataType == "day"){
				var nowDate = new Date();
				$scope.daytime=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
			}
			// 周查询条件，其中年份是公用的
			$scope.yearlist=[];
			var currentYear=(new Date()).getFullYear();
			for(var i=0;i<4;i++){
				$scope.yearlist.push({
					name:currentYear-i+"年",
					value:currentYear-i+""
				});
			}; 
			$scope.selectYear=currentYear+"";
			$scope.selectYeary=currentYear+"";
			$scope.changeYear($scope.selectYear);
			// 月查询条件
			$scope.monthlist=[];
			for(var i=1;i<=12;i++){
				$scope.monthlist.push({
					name:i+"月",
					value:""+i
				});
			};
			$scope.selectMonth=((new Date()).getMonth() + 1)+"";
			$scope.selectMonthy=((new Date()).getMonth())+"";
			// 季度查询条件
			$scope.quarterslist=[
			                 {name:"第1季度",value:"1"},
			                 {name:"第2季度",value:"2"},
			                 {name:"第3季度",value:"3"},
			                 {name:"第4季度",value:"4"}
			                ];
			$scope.selectQuarter = ""+ (Math.floor(((new Date).getMonth()+1)/4)+1);//获取当前季度
			_getList();
		};
		// 选择年份更新周信息
		$scope.changeYear = function(year){
			$scope.weeklist = $DataReportService.getYearWeek(year);
			$scope.selectWeek= $scope.weeklist[0].value;
			for(var i=0;i<$scope.weeklist.length;i++){
				var week = $scope.weeklist[i];
				if(week.today){
					$scope.selectWeek = week.value;
				}
			}
		}
		//获取统计时间
		function getQueryObj(){
			if($scope.dataType == null){
				return null;
			}
			var queryObj = {};
			if($scope.dataType == "month"){//月
				queryObj.startDate =$scope.selectYear + "-" + $scope.selectMonth +"-01";
				var  day = new Date($scope.selectYear,$scope.selectMonth,0).getDate(); 
				queryObj.endDate =$scope.selectYear + "-" + $scope.selectMonth +"-"+day;
			}
			else if($scope.dataType == "quarter"){//季度
				var startMonth = 1 + (parseInt($scope.selectQuarter) - 1) * 3;
				queryObj.startDate =$scope.selectYear + "-" + startMonth + "-01";
				var  day = new Date($scope.selectYear,startMonth+2,0).getDate(); 
				queryObj.endDate =$scope.selectYear + "-" + (startMonth+2) +"-"+day;
			}
			else if($scope.dataType == "year"){//年
				var startMonth = 1 + (parseInt($scope.selectQuarter) - 1) * 3;
				queryObj.startDate =$scope.selectYear + "-01-01";
				queryObj.endDate =$scope.selectYear  + "-12-31";
			}
			queryObj.dataType=$scope.dataType;
			queryObj.selectQuarter=$scope.selectQuarter;
			$scope.queryObj.year=$scope.selectYear;
			$scope.queryObj.Month=$scope.selectMonth;
			$scope.queryObj.STARTDATE=queryObj.startDate;
			$scope.queryObj.ENDDATE=queryObj.endDate;
		}
		$scope.initQuery();//默认按当月查询
	});
}(window, angular));	